package com.nb.provider.serviceimpl;

import com.google.common.collect.Lists;
import com.nb.api.dto.UserDTO;
import com.nb.api.model.User;
import com.nb.api.service.UserServiceAPI;
import org.apache.dubbo.config.annotation.DubboService;

import java.util.List;
import java.util.Random;

@DubboService//定义一个dubbo服务
public class UserServiceApiImpl implements UserServiceAPI {



    @Override
    public User getById(int id) {
        return User.builder()
                .id(id)
                .mobile("13888888888")
                .sex(1)
                .username("牛~呗"+id)
                .build();
    }

    @Override
    public User addUser(UserDTO userDTO) {
        return User.builder()
                .id(new Random().nextInt())
                .mobile(userDTO.getMobile())
                .sex(userDTO.getSex())
                .username(userDTO.getUsername())
                .build();
    }

    @Override
    public List<User> getUserList() {
        return Lists.newArrayList(User.builder()
                .id(111)
                .mobile("13888888888")
                .sex(1)
                .password("122345")
                .username("牛~呗"+111)
                .build(),
                User.builder()
                        .id(222)
                        .mobile("1399999999999")
                        .sex(2)
                        .password("4567788")
                        .username("西决"+222)
                        .build(),
                User.builder()
                        .id(333)
                        .mobile("1366666666")
                        .sex(1)
                        .password("787554")
                        .username("阿痞"+333)
                        .build()
                );
    }
}
